package week_02;

import java.util.ArrayList;
import java.util.List;

public class CombineSet_77 {
    private List<List<Integer>> ans;
    private List<Integer> subset;
    private int num;
    private int k;

    public List<List<Integer>> combine(int n, int k) {
        //输入：nums = [1,2,3]
        //输出：[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
        this.k = k;
        num = n;
        ans = new ArrayList<>();
        subset = new ArrayList<>();
        int index = 1;
        clac(index);
        return ans;
    }

    public void clac(int index) {
        System.out.println(index);
        if (subset.size() > k || subset.size() + num - index + 1 < k) return;
        if (index == num+1 ) {
            ans.add(new ArrayList<>(subset));
            return;
        }
        //不加这个数
        clac(index + 1);
        //加这个数
        subset.add(index);
        clac(index + 1);
        subset.remove(subset.size() - 1);
    }
}
